<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class SessionController extends Controller
{
    //
    public function create(){

        return view('sessions.create');
    }

    public function store(Request $request){

       $credentials = $this -> validate($request,[

            'email' => 'required|email|max:255',
            'password' => 'required'

        ]);
       if (Auth::attempt($credentials,$request -> has('remember'))){
           //登陆成功后的操作
           session() -> flash('sucess','欢迎回来');
           return redirect() -> route('users.show',[Auth::user()]);
       }
       else{
           //登陆失败后的操作
           session() -> flash('danger','很抱歉，您的邮箱密码不匹配');
           return redirect() ->back() ->withInput();
       }
       return;

    }
    public function destroy(){

        Auth::logout();
        session() -> flash('success','您已成功退出');
        return redirect('login');
    }
}
